<script>
    $(function () {
        var form = new Vue({
            el:'#form',
            data:{
                service_type:window.service_type,
                delivery:window.delivery,
                carry:window.carry,
                install:window.install,
                repair:window.repair,
            },
            mounted:function(){
                for (i in this.service_type){
                    var checkbox = $('input:checkbox#checkbox_'+service_type[i]);
                    checkbox.attr('checked','checked');
                    checkbox.parent('label').addClass('zc01_hover');
                }
            },
            methods:{
                check: function(event){
                    var that = event.target;
                    if (that.checked){
                        $(that).parent('label').addClass('zc01_hover');
                    }else{
                        $(that).parent('label').removeClass('zc01_hover');
                    }

                    var partCheckbox = $(that).parents('div:eq(0)').find('h2 input:checkbox');
                    var childCheckbox = $(that).parents('div:eq(0)').find('ul input:checkbox');
                    partCheckbox.get(0).checked = childCheckbox.filter(':checked').length > 0;
                },
                checkPartAll: function( event ) {
                    var that = event.target;

                    var children = $(that).parents('div:eq(0)').find('ul input:checkbox');
                    var dom = children.get();
                    for (i=0;i<dom.length;i++){
                        dom[i].checked = that.checked;
                    }
                    if (that.checked){
                        children.parent('label').addClass('zc01_hover');
                    }else{
                        children.parent('label').removeClass('zc01_hover');
                    }
                },
            }
        });

        var validator = $("#form").validate({
            rules: {
                'service_type[]':{
                    required:true
                },
            },
            messages: {
                'service_type[]':{
                    required:'请选择服务类型'
                },
            },
            submitHandler: function(form) {
                form.submit();
            },
        });
    });
</script>